<template>
  <div>
        <div>{{teacher.name}}</div>
        <div>{{teacher.age}}</div>
        <div>{{teacher.salary}}</div>
        <button @click="timeFly">过了一年</button>
   </div>
</template>
 
<script>
export default {
  data() {
    return {
       teacher:{
        name:"harry",
        age:28,
        salary:3000
      }
    };
  },
  methods: {
   timeFly() {
      this.teacher.age += 1
      this.teacher.salary += 500
    }
  },
  // 普通
  watch:{
    "teacher.age"(newVal) {
       if(newVal > 40) {
        alert('你该退休了')
       }
    }

  },
  // 深度监听
  // watch: {
  //     teacher:{
  //     deep:true,
  //     handler(newVal, oldVal) {
  //       console.log(newVal, oldVal);
  //     }
  //     },
  // }
};
</script>

<style scoped>
     
</style>